﻿namespace Rsdn.SmartApp
{
    using System;

    /// <summary>
    /// Represents a path.
    /// </summary>
    public class Path<T>
    {
        private readonly T _lastPathComponent;
        private readonly int _length;
        private readonly Path<T> _parentPath;

        /// <summary>
        /// Initialize instance.
        /// </summary>
        public Path(T lastPathComponent)
            : this(null, lastPathComponent)
        {
        }

        /// <summary>
        /// Initialize instance.
        /// </summary>
        public Path(Path<T> parentPath, T lastPathComponent)
        {
            this._parentPath = parentPath;
            this._lastPathComponent = lastPathComponent;
            this._length = (this.ParentPath != null) ? (this.ParentPath.Length + 1) : 1;
        }

        /// <summary>
        /// Returns the last component of this path.
        /// </summary>
        public T LastPathComponent
        {
            get
            {
                return this._lastPathComponent;
            }
        }

        /// <summary>
        /// Returns the number of elements in the path.
        /// </summary>
        public int Length
        {
            get
            {
                return this._length;
            }
        }

        /// <summary>
        /// Returns a path containing all the elements of this path, except the last path component.
        /// </summary>
        public Path<T> ParentPath
        {
            get
            {
                return this._parentPath;
            }
        }
    }
}

